<?php
/**
 * @package Joomla
 * @subpackage Jmonoslideshow
 * @copyright (C) 2010 - Matthieu BARBE - www.ccomca.com
 * @license GNU/GPL v2
 * 
 * Jmonoslideshow is a Joomla extension for Monoslideshow.
 *
 * Jmonoslideshow uses :
 * Monoslideshow (http://www.monoslideshow.com/)
 * Plupload (http://www.plupload.com/) by Moxicode Systems
 * json class by Michal Migurski, Matt Knapp, Brett Stimmerman
 * jquery a JavaScript Library (http://jquery.com/)
 * getid3 library (http://getid3.sourceforge.net/)
 * swfobject is an easy-to-use and standards-friendly method to embed Flash content, which utilizes one small JavaScript file (http://code.google.com/p/swfobject/)
 * Chained Selects jQuery Plugin (http://www.appelsiini.net/2010/jquery-chained-selects)
 *
 * Jmonoslideshow is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

jimport('joomla.application.component.model');

/**
 * @package		Joomla
 * @subpackage	Jmonoslideshow
 */
class JmonoslideshowModelSlideshow extends JModel
{
	/**
     * Returns a list of medias
     */
    public function getMedias($params)
    {
        $db = &JFactory::getDBO();
		//filter category display
		$where = "";
		$category = $params->get('category', "0");
		if ($category)
		{ 
    		if( is_array( $category ) ) {
        	$catCondition = ' AND (catid IN ( ' . implode( ',', $category ) . ') )';
	    	} else {
			$catCondition = ' AND (catid = '.$category.')';
			}	
		}

		if ($category != 0) $where .= $catCondition; else $where .= "";
		
		//filter media type
		$typemedia = $params->get('typemedia', "all");
		if ($typemedia != "all")
		{ 
    		if( is_array( $typemedia ) ) {
        	$typeCondition = ' AND (type IN ( ' . implode( ',', $typemedia ) . ') )';
	    	} else {
			$typeCondition = ' AND (type = '.$typemedia.')';
			}	
		}

		if ($typemedia != "all") $where .= $typeCondition; else $where .= "";
		
		$order = $params->get('order_image', "random");
		if ($order == "random")
			{
				$orderby = "rand()";
			}
			else if ($order == "order_asc")
			{
				$orderby = "ordering ASC";
			}
			else
			{
				$orderby = "ordering DESC";
			}
		
        
        $query = 'SELECT * FROM `#__monoslideshow` WHERE published = 1 '.$where.' ORDER BY '.$orderby.' LIMIT '.$params->get('show_media', "5");
        
		return $this->_getList( $query );
        
 
      
    } //end getItems
}